package 笔试;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Date 2024/10/12 19:00
 * @description: 美团笔试
 * .
 * @Author LittleNight
 */
public class meituan1 {

    public static void main333(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(34);
        list.add(1);
        list.add(10);
        list.sort((o1, o2) -> o2 - o1);
        System.out.println(list);

        StringBuffer sb = new StringBuffer("abcd");
        sb.delete(1, 2);
        System.out.println(sb);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt(), b = in.nextInt();
            int[] arr = new int[a], brr = new int[b];
            int ret = 0;
            for(int i = 0; i < a; i++) {
                arr[i] = in.nextInt();
            }
            for(int i = 0; i < b; i++) {
                brr[i] = in.nextInt();
            }
            if(a > b) {
                for (int i = 0; i < b; i++) {
                    ret += arr[i];
                    ret += brr[i];
                }
            }else {
                for (int i = 0; i < a; i++) {
                    ret += arr[i];
                    ret += brr[i];
                }
            }
            System.out.println(ret);
        }
    }

    // 过了百分之 20
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int k = in.nextInt();
            char[] ch = in.next().toCharArray();
            int n = ch.length;
            int[] arr = new int[n];
//            List<Integer> list = new ArrayList<>();
            List<String> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                // 遇到数字. 提取出来全部的整数
                if(ch[i] >= '0' && ch[i] <= '9') {
                    int num = 0;
                    StringBuffer sb1 = new StringBuffer();
                    while(i < n && ch[i] >= '0' && ch[i] <= '9') {
                        // num = num * 10 + (ch[i] - '0');
                        sb1.append(ch[i]);
                        i++;
                    }
                    i--;
                    // 提取出来之后，进行计算
                    if(sb1.charAt(0) == '0' && sb1.length() > 1) {
                        // 处理掉前置0
                        int index = 0;
                        while(index < sb1.length()&&sb1.charAt(index) == '0') {
                            sb1.deleteCharAt(index++);
                        }
                        // sb1.delete()
                    }
                    // 添加到结果中
//                    list.add(Integer.parseInt(sb1.toString()));
//                    list.add(Double.parseDouble(sb1.toString()));
                    list.add(sb1.toString());
                }
            }
            // list 降序排序
            list.sort((o1, o2) -> o2.compareTo(o1));
            if(k > list.size()) System.out.println('N');
            else System.out.println(list.get(k - 1));
        }
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt(), ret = 0;
            int[] arr = new int[n];
            // boolean flag = false;
            for(int i = 0; i < n; i++) {
                boolean flag = false;
                char[] ch = in.next().toCharArray(); // 拿到数字
                int sum = 0;
                // 进行判断
                for(int j = 0; j < ch.length; j++) {
                    if(ch[j] % 2 == 1) {
                        flag = true;
                    }
                    // 位数之和
                    sum += ch[j] - '0';
                }
                if(flag && sum % 2 == 0) ret++;
            }
            System.out.println(ret);
        }
    }

}
